import 'package:flutter/material.dart';
import 'package:flutter_account_book/utils/db/db_helper.dart';
import 'package:flutter_account_book/utils/db/entities/account_book.dart';
import 'package:get/get.dart';

class AnalysisLogic extends GetxController {
  Future<List<Map<String, Object?>>> getTotalAmountPerDay(
      int id, DateTimeRange range, bool isIncome) async {
    if (id == AccountBook.idAll) {
      return isIncome
          ? DbHelper.helper.accountRecordDao
              .getTotalIncomeAmountPerDayByRange(range)
          : DbHelper.helper.accountRecordDao
              .getTotalExpendAmountPerDayByRange(range);
    }
    return isIncome
        ? DbHelper.helper.accountRecordDao
            .getTotalIncomeAmountPerDayByBookIdAndRange(id, range)
        : DbHelper.helper.accountRecordDao
            .getTotalExpendAmountPerDayByBookIdAndRange(id, range);
  }

  Future<List<Map<String, Object?>>> getTotalRecordTypeAmountPerDay(
      int id, DateTimeRange range, bool isIncome) async {
    if (id == AccountBook.idAll) {
      return isIncome
          ? DbHelper.helper.accountRecordDao
              .getTotalIncomeRecordTypeAmountPerDayByRange(range)
          : DbHelper.helper.accountRecordDao
              .getTotalExpendRecordTypeAmountPerDayByRange(range);
    }
    return isIncome
        ? DbHelper.helper.accountRecordDao
            .getTotalIncomeRecordTypeAmountPerDayByByBookIdAndRange(id, range)
        : DbHelper.helper.accountRecordDao
            .getTotalExpendRecordTypeAmountPerDayByByBookIdAndRange(id, range);
  }
}
